/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *    2012 year
 *    Author: Michael Khromov aka MikeDM (Mike D'Morto)
 *    E-Mail: mikedmorto@gmail.com
 */

#ifndef WORKER_H
#define WORKER_H
#define WRK_NAME "dbconnector_mysql_worker"

#define DEF_DBPORT 3306

#include <QThread>
#include <QtSql>

class Worker : public QThread
{
    Q_OBJECT
    // конфигурация базы данных
    QString dbhost,dbsocket,dbname,dbusername,dbpassword;
    int dbport;
    QString sessionID;
    // флаг остановки
    bool isStop;
    void run();
    QString sqlsafe(const QString & srt);
public:
    explicit Worker(const QString &cfg,const QString sessionID, QObject *parent = 0);
    void stopT();
signals:
    void sigPutLog(const QString & owner, int level, const QString & text);
    void sigFinish( const QString & sesstioID, QStringList data);
    void sigError(const QString & sessionID, const QString & errtext);
public slots:
    // начало транзакции для потока
    void slotTransactionStart();
    // окончание транзакции для потока - commit
    void slotTransactionCommit();
    // окончание транзакции для потока - rollback
    void slotTransactionRollback();
    // запрос метафункции
    void slotQuery(const QString & metafunction, QStringList params);
    
};

#endif // WORKER_H
